---
title: "Replication file for \"Once We Too Were Strangers\""
author: "Nicholas Sambanis, Matthew D. Simonson, and Şule Yaylacı"
date: "10/23/2023"
output:
  html_document:
    toc: true
    toc_depth: 3
    toc_float: true
editor_options: 
  markdown: 
    wrap: 72
---

# Setup

## Packages and Settings

```{r, message=FALSE}
rm(list=ls())
cat("\14")
library(tidyverse)
library(fixest)
library(data.table)

# For Tables
library(kableExtra)
library(xtable)
library(gt)
library(gtsummary)
library(modelsummary)
library(vtable)
library(stargazer)

# For plots
library(jtools)
library(patchwork)
library(ggtext)

# For matching
library(MatchIt)
library(cobalt)

# For meta-analysis
library(metafor)

set.cobalt.options(binary = "std")
setFixest_etable(digits = 2, depvar = T)
setFixest_vcov(no_FE = "hetero")

# for ggplot plot (format: new = old)
coef_renaming_vec <- c(
               "refugee family" = "refugee_family", 
               "treated" = "treat_parallel",
               "treated x\nrefugee family" = 
                 "refugee_family:treat_parallel"
)



se_setting <- T
suppress_controls <- T

dir.create("Figures")
dir.create("Tables")

```

## Functions

```{r setup}
std <- function(x) (x - mean(x, na.rm = T))/sd(x, na.rm = T)

make_formula <- function(char_vec){
  char_vec %>% paste(collapse = " + ") %>% paste("~", .) %>% as.formula()
}

# takes a fixest object and extracts estimate, CI, and regressor's name
  # for a regressor you specify (or all of them)
est_and_ci <- function(model, keep=NULL, CI_level = .95, 
                       inner_CI_level = NULL, model_name=NULL,
                       R2=F, nparams=F){
  out <- bind_cols(
    regressor = names(coef(model)),  # no fixest function can do this
    dv = formula(model)[[2]] %>% as.character(), # no fixest function can do this
    N = nobs(model),
    low = confint(model, level = CI_level)[,1],
    estimate = coef(model), 
    high = confint(model, level = CI_level)[,2],
    se = se(model),
    t.stat = tstat(model),
    p.value = pvalue(model)) %>%
    mutate(
    stars = case_when(p.value<0.001 ~ "***",
                      p.value<0.01 ~ "**",
                      p.value<0.05 ~ "*",
                      p.value<0.1 ~ ".",
                      T~"")
  )
  
  if(R2==T) out <- out %>% mutate(R2 = model[["sq.cor"]])
  if(nparams==T) out <- out %>% mutate(nparams = model[["nparams"]])
  
  if(!is.null(inner_CI_level)){
    out <- out %>% mutate(
      low_inner= confint(model, level = inner_CI_level)[,1],
      high_inner = confint(model, level = inner_CI_level)[,2],
    ) %>% 
      relocate(low_inner, .before = estimate) %>%
      relocate(high_inner, .after = estimate)
  }
  if(!is.null(keep)) out <- out %>% filter(regressor %in% keep)
  if(!is.null(model_name)) out <- out %>% mutate(model = model_name) %>% relocate(model)

  out
}

# this is merely a wrapper for est_and_ci that can handle fixest output
# regardless of whether that output contains one regression or several
prep_for_plot  <- function(fixest.object, keep=NULL, CI_level = 0.95, 
                           inner_CI_level = NULL, model_name = NULL,
                           R2=F, nparams=F){
  if(class(fixest.object) == "fixest"){
    est_and_ci(model = fixest.object, 
               CI_level = CI_level, 
               inner_CI_level = inner_CI_level, 
               keep=keep, 
               model_name = model_name,
               R2=R2, 
               nparams=nparams)
  } else if(class(fixest.object) == "fixest_multi"){
    map(fixest.object, est_and_ci, 
        CI_level = CI_level, 
        inner_CI_level = inner_CI_level, 
        keep=keep, 
        model_name = model_name,
        R2=R2, 
        nparams=nparams) %>% 
      rbindlist()
  } else {
    warning("fixest.object must be a fixest or fixest_multi object")
  } 
}
```

## Control Variables

```{r controls}
# for etable (format: old = new)
setFixest_dict(c("refugee_family" = "refugee family",
                 "attitude_mean" = "attitude mean",
                 "att_mean" = "att. mean",
                 "treat_parallel" = "treated",
                 "treat_acknowledge" = "acknowledge",
                 "admit_refugee" = "admissions",
                 "work_permit" =  "permit",
                 "donation_amount" = "don. amount",
                 "therm_syrian" = "therm refugees",
                 "donate_log" = "log(don. amount)",
                 "donation_amount_log" = "log(don. amount)",
                 "open_camp" = "open camp",
                 "single_men" = "men",
                 "hh_size" = "household size",
                 "asylum_num" = "asylum",
                 #"kyrenia100" = "kyrenia (binary)",
                 #"ref_suffer_more" = "ref suffer more",
                 "pt_vignette" = "PT vignette",
                 "low_income" = "low income",
                 "balkan_imm_family" = "balkan imm family",
                 "parent_lang" = "parent language",
                 "foreign_parent"= "foreign parent",
                 "freq_contact" = "freq contact",
                 "estimate_Syrian_pct" = "est. Syrian %",
                 "church_freq" = "church freq.",
                 "estimate_Syrian_N" = "est. Syrian N",
                 "club_member" = "club member",
                 "abroad_ever" = "abroad ever",
                 "landsea_treatment" = "land/sea treatment",
                 "baseline_index" = "attitude mean (pre-treat)",
                 "therm_english" = "therm english", 
                 "therm_greek" = "therm greek", 
                 "therm_turk" = "therm turk", 
                 "therm_homosexual" = "therm homosexual",
                 "therm_cypriot" = "therm cypriot",
                 "therm_refugee" = "therm refugee (pre-treat)",
                 "hire_imm" = "hire immigrant",
                 "asylum_all" = "asylum (pre-treat): admit all",
                 "asylum_none" = "asylum (pre-treat): admit none",
                 "abroad_yearround" = "abroad year-round", 
                 "heard_of_pournara" = "heard of pournara",
                 "freq_see_asylum" =  "freq. see asylum", 
                 "freq_speak_asylum" = "freq. speak asylum" , 
                 "violence_family" = "violence family",
                 "therm_german" ="therm german" , 
                 "therm_iraqi" = "therm iraqi",
                 "therm_filipino" = "therm filipino", 
                 "therm_nigerian" ="therm nigerian",
                 "job_type" = "job type",
                 "ref_status" = "refugee status",
                 "occ73_dad" = "dad job in '73",
                 "occ73_mom" = "mom job in '73",
                 
                 "asiaminor" = "Asia Minor",
                 "tr" = "treated",
                 "pontic" = "Pontic",
                 "stories_fam" = "family stories",
                 "stories_nei" = "neighbor stories",
                 "asia_T" = "total effect on Asia Minor",
                 "museum_donate" = "museum donation",
                 "pc_behavior" =      "Quasi-behavioral",
                 "pc_attitude_full" = "Attitudes       ",
                 "mean_behavior" =      "Average behavioral",
                 "mean_attitude_full" =      "Average attitudinal",
                 "pc_attitude_core" = "PCA attitudinal (strict)"
))

ctrls.turk <- c(
  "age", "male", "freq_contact", "foreign_parent",
  "district", "estimate_Syrian_pct", "balkan_imm_family",
  "parent_lang", "parent",
  "unemployed", "college", "low_income", "pt_vignette"
  #"party", "religiosity",
)

# ctrls.turk.R1 <- c(
#   "age", "male", #"freq_contact", 
#   "foreign_parent",
#   "district", #"estimate_Syrian_pct", 
#   "balkan_imm_family",
#   "parent_lang", "parent",
#   "unemployed", "college", "low_income", "pt_vignette"
#   #"party", "religiosity",
# )

ctrls.turk.not.in.pap <- c(
  "freq_contact", "foreign_parent",
  "district", "estimate_Syrian_pct", "parent"
)

outcomes.turk <- c("concern", "admissions", "permits", 
          "therm_syrian", "donate", "donation_amount", "letter",
          "donation_amount_log")


ctrls.2018 <- c("age", "male", "occ73_dad", "occ73_mom")

ctrls.2018.alt <- c("age", "male", "district", "married", "parent", 
         "unemployed", "lived_abroad", "voted", "church_freq", "class", "college")

outcomes.2018 <- c("asylum_num", 
                   "kyrenia_max")

ctrls.2021 <- c("male", "age", "foreign_parent", "orthodox", "freq_contact",
           "estimate_Syrian_N", #"landsea_land", "landsea_Syria", 
           "landsea_treatment",
           "therm_english", "therm_greek", "therm_turk", "therm_homosexual",
           "therm_cypriot", #"therm_outgroup",
           "asylum_all", "asylum_none", "therm_refugee", "baseline_index",
           "church_freq", "club_member", "parent", "voted", "college",
           "unemployed", "tourism", "hire_imm", "income", "abroad_ever")

# ctrls.2021.R1 <- c("male", "age", "foreign_parent", "orthodox", #"freq_contact",
#            #"estimate_Syrian_N", #"landsea_land", "landsea_Syria", 
#            "landsea_treatment",
#            #"therm_english", "therm_greek", "therm_turk", "therm_homosexual",
#            #"therm_cypriot", #"therm_outgroup",
#            #"asylum_all", "asylum_none", #"therm_refugee", 
#            #"baseline_index",
#            "church_freq", "club_member", "parent", "voted", "college",
#            "unemployed", "tourism", #"hire_imm", 
#            "income", "abroad_ever")



outcomes.2021 <- c("concern", "donate", "donation_amount")

# ctrls.2022 <- c("male", "age" , "college" , "foreign_parent",
#                 "abroad_yearround", "rural" , "heard_of_pournara",
#                 "freq_see_asylum" , "freq_speak_asylum" ,
#                 "therm_english", "therm_german" , "therm_iraqi",
#                 "therm_filipino" , "therm_turk" ,
#                 "therm_nigerian" , "therm_cypriot")
# 
# ctrls.2022.pap <- c(ctrls.2022, "voted" , "parent",
#                 "unemployed" , "income_refused" ,
#                 "low_income", "hh_size")
# 
# ctrls.2022.cat <- c(ctrls.2022, "voted_cat" , "parent_cat",
#                 "employment_cat" , "income_cat" ,
#                 "hh_size_cat")

ctrls.2022 <- c("male", "age" , "college", "foreign_parent",
                "abroad_yearround", "rural", "heard_of_pournara",
                "freq_see_asylum" , "freq_speak_asylum" , "violence_family",
                "therm_english", "therm_german" , "therm_iraqi",
                "therm_filipino" , "therm_turk" ,
                "therm_nigerian" , "therm_cypriot",
                "voted", "parent", "job_type", "income", "hh_size")

ctrls.2022.alt <- c("male", "age" , "college", "foreign_parent",
                "abroad_yearround", "rural", "heard_of_pournara",
                "freq_see_asylum" , "freq_speak_asylum" ,
                "therm_english", "therm_german" , "therm_iraqi",
                "therm_filipino" , "therm_turk" ,
                "therm_nigerian" , "therm_cypriot",
                "voted_enc", "parent_enc", "employed_enc", "income", "hh_size_enc")


# ctrls.2022.R1 <- c("male", "age" , "college", "foreign_parent",
#                 "abroad_yearround", "rural", #"heard_of_pournara",
#                 #"freq_see_asylum" , "freq_speak_asylum" , 
#                 "violence_family",
#                 #"therm_english", "therm_german" , "therm_iraqi",
#                 #"therm_filipino" , "therm_turk" ,
#                 #"therm_nigerian" , "therm_cypriot",
#                 "voted", "parent", "job_type", "income", "hh_size")

outcomes.2022 <- c("children", "families", "open_camp", 
              "permits", "admissions", "single_men",
              "letter")


setFixest_fml(
  
  ..ctrls.dinas = ~ female + i(age) + i(edu) + 
                i(occupation) + i(income) + i(prefecture),
  
  ..ctrls.greece = ~ female + i(age) + i(edu) + 
                i(occupation) + i(income) + i(prefecture),
  
  ..ctrls.turk = make_formula(ctrls.turk),
  
  #..ctrls.turk.cat = make_formula(ctrls.turk.cat),
  
  ..ctrls.turk.pap = ~ pt_vignette + balkan_imm_family +
    male + age + college + religiosity + unemployed + party_original + 
    parent_lang + low_income,
  
  ..ctrls.2018 = make_formula(ctrls.2018), 
  
  ..ctrls.2018.alt = make_formula(ctrls.2018.alt), 
  
  ..ctrls.2021 = ~male + age + foreign_parent + orthodox + i(freq_contact) + estimate_Syrian_N + 
    i(landsea_treatment) + therm_english + therm_greek + therm_turk + 
    therm_homosexual + therm_cypriot + asylum_all + asylum_none + therm_refugee + 
    baseline_index + church_freq + club_member + parent + voted + 
    college + unemployed + tourism + hire_imm + i(income) + abroad_ever,
  

  
  ..ctrls.2022 = ~ male + age + college + foreign_parent + abroad_yearround + rural + 
    heard_of_pournara + freq_see_asylum + freq_speak_asylum + 
    violence_family + therm_english + therm_german + therm_iraqi + 
    therm_filipino + therm_turk + therm_nigerian + therm_cypriot + 
    voted + parent + i(job_type) + i(income) + hh_size,
  
  ..ctrls.2022.alt = make_formula(ctrls.2022.alt)#,
  #..ctrls.2022.cat = make_formula(ctrls.2022.cat),
  #..ctrls.2022.pap = make_formula(ctrls.2022.pap),
  #..ctrls.turk.R1 = make_formula(ctrls.turk.R1),
  #..ctrls.2021.R1 = make_formula(ctrls.2021.R1),
  #..ctrls.2022.R1 = make_formula(ctrls.2022.R1)
)
```

## Load data

```{r loading}
load("Once_We_Too_Data.Rdata")
```

### Guide to the data.frames:

1.  dinas - Data from Dinas et al. (2021) paper

2.  g.2020 - Data from Greece 2022 study

3.  t.2021 - Data from Turkey 2021 study

4.  c.2018 - Data from Cyprus 2018 study

5.  c.2021 - Data from Cyprus 2021 study

6.  c.2022 - Data from Cyprus 2022 study

7.  c.3arms - Data from Cyprus 2022 study including the "acknowledgement
    of suffering" treatment arm

8.  c.2022.nome - Data from Cyprus 2022 study excluding first generation
    refugees

# Published Article

## Main Regressions

For each study, we run two regressions.

1.  First we run a linear regression with the interaction term
    `refugee_family*treat_parallel` for all the outcomes and controls
    specified in the appendix

2.  Second, re-run the same regression with the terms
    `refugee_family + refugee_T + nonrefugee_T` where `refugee_T` is a
    dummy variable for respondent being from refugee family in the
    treatment group while `nonrefugee_T` is an indicator for being from
    a non-refugee in the treatment group. This regression is run in
    order to show the total effect of treatment on refugee families
    (this is the same method used to Dinas et al. 2021).

```{r}
# Greece study
M.greek <- g.2022 %>% 
  feglm(c(attitude_mean, donate) ~ refugee_family*treat_parallel +
              female + age + i(edu) + 
                i(occupation) + income | prefecture, vcov = ~municipality) 

M.greek.total <- g.2022 %>% 
  feglm(c(attitude_mean, donate) ~ refugee_family + refugee_T + nonrefugee_T +
              female + age + i(edu) + 
                i(occupation) + income | prefecture, vcov = ~municipality) 

# Turkey study
M.turk <- t.2021 %>%
  feglm(data = ., 
        c(attitude_mean, donate)~ 
          refugee_family*treat_parallel + age + male + freq_contact +
          foreign_parent + estimate_Syrian_pct + balkan_imm_family +
          i(parent_lang) + parent + unemployed + college + low_income +
          pt_vignette | district)

M.turk.total <- t.2021 %>%
  feglm(data = ., 
        c(attitude_mean, donate)~ 
          refugee_family + refugee_T + nonrefugee_T +
          age + male + freq_contact +
          foreign_parent + estimate_Syrian_pct + balkan_imm_family +
          i(parent_lang) + parent + unemployed + college + low_income +
          pt_vignette | district)

# Cyprus 2018 study
M.cyp.2018 <- c.2018 %>% 
  feglm(data = ., 
        c(asylum_num) ~
          refugee_family*treat_parallel + age + male + 
          i(occ73_dad) + i(occ73_mom), 
        cluster = "municipality")

M.cyp.2018.total <- c.2018 %>% 
  feglm(data = ., 
        c(asylum_num) ~
          refugee_family + refugee_T + nonrefugee_T +
          age + male + 
          i(occ73_dad) + i(occ73_mom), 
        cluster = "municipality")



# Cyprus 2021 study
M.cyp.2021 <- c.2021 %>%
  feglm(data = ., 
        c(concern, donate) ~
          refugee_family*treat_parallel + ..ctrls.2021)

M.cyp.2021.total <- c.2021 %>%
  feglm(data = ., 
        c(concern, donate) ~
          refugee_family + refugee_T + nonrefugee_T + ..ctrls.2021)

# Cyprus 2022 study
M.cyp.2022 <- c.2022 %>%
  mutate(drop_first_gen = case_when(first_gen_refugee==1~NA,
                                 T ~ T)) %>%
  feglm(data = ., 
        c(attitude_mean, letter) ~ 
          refugee_family*treat_parallel + ..ctrls.2022 + sw0(drop_first_gen))

M.cyp.2022.total <- c.2022 %>%
  mutate(drop_first_gen = case_when(first_gen_refugee==1~NA,
                                 T ~ T)) %>%
  feglm(data = ., 
        c(attitude_mean, letter) ~ 
          refugee_family + refugee_T + nonrefugee_T + ..ctrls.2022 + sw0(drop_first_gen))


```

## Figure 1

### Extract data

Here we extract the relevant statistics from each regression, renaming
variables as needed as organizing the results into a tibble, using the
`prep_for_plot` function defined at the beginning of this file.

```{r}
combined_results_attitude <- bind_rows(
  # Net effect of treatment on refugee families
  prep_for_plot(M.greek.total[[1]], 
                keep = "refugee_T",
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "1. Greece"),
  prep_for_plot(M.turk.total[[1]], 
                keep = "refugee_T", 
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "2. Turkey"),
  prep_for_plot(M.cyp.2018.total, 
                keep = "refugee_T", R2 = T, nparams = T,
                inner_CI_level = .9,
                model_name = "3. Cyprus 2018"),
  prep_for_plot(M.cyp.2021.total[[1]], 
                keep = "refugee_T",
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "4. Cyprus 2021"),
  prep_for_plot(M.cyp.2022.total[[1]], 
                keep = "refugee_T",
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "5. Cyprus 2022"),
  
  # Coefficient estimates for treatment, refugee family, and their interaction
  prep_for_plot(M.greek[[1]], 
                keep = coef_renaming_vec,
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "1. Greece"),
  prep_for_plot(M.turk[[1]], 
                keep = coef_renaming_vec, 
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "2. Turkey"),
  prep_for_plot(M.cyp.2018, 
                keep = coef_renaming_vec,
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "3. Cyprus 2018"),
  prep_for_plot(M.cyp.2021[[1]], 
                keep = coef_renaming_vec,
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "4. Cyprus 2021"),
  prep_for_plot(M.cyp.2022[[1]], 
                keep = coef_renaming_vec,
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "5. Cyprus 2022")) %>% 
  arrange(regressor)
```

### Plot

```{r}
combined_results_attitude %>% 
  mutate(
    Study = fct_rev(paste0( model, "\n(N = ", scales::comma(N), ")\n")),
    Outcome = fct_rev(dv),
    regressor = fct_rev(
      recode_factor(
        regressor, 
        "refugee_family" = "refugee family",
        "treat_parallel" = "treated",
        "refugee_family:treat_parallel" = "treated x\nrefugee family",
        "refugee_T" = "net effect of treatment\non refugee familes"))) %>%
  ggplot(aes(x = estimate, y=regressor, color = Study, shape =Study)) + 
  geom_pointrange(aes(xmin = low, xmax = high), 
                  position = position_dodge(width = 0.6)) +
  geom_linerange(aes(xmin = low_inner, xmax = high_inner), size = 1.2,
                 position = position_dodge(width = 0.6)) +
  labs(x = "Effect on Pro-Refugee Attitudes (in SDs)", 
       y = "Predictor",
       #caption = main_capt
       )  +
  guides(color = guide_legend(reverse = T),
         shape = guide_legend(reverse = T)) +
  scale_color_manual(values = get_colors("CUD Bright", 5))+
  theme_bw() + 
  geom_vline(xintercept = 0, lty = "dashed") +
  theme(#axis.title.y=element_blank(),
          axis.ticks.y = element_blank(),
          panel.grid.major.y=element_blank(),
          panel.grid.minor.y=element_blank(),
          plot.caption.position = "plot")
ggsave("Figures/Figure_1.png", width = 6, height = 3.6)

```

## Figure 2

### Extract data

```{r}
# Meta Analysis: treatment
meta_re_treat <- 
  combined_results_attitude %>% 
  filter(regressor == "treat_parallel") %>%
  metafor::rma(measure="PCOR", 
      ti = t.stat,
      ni = N,
      mi = nparams,
      r2i = R2, 
      data = .,
      slab = model)

# Meta Analysis: refugee family
meta_re_refguee <- 
  combined_results_attitude %>% 
  filter(regressor == "refugee_family") %>%
  metafor::rma(measure="PCOR", 
      ti = t.stat,
      ni = N,
      mi = nparams,
      r2i = R2, 
      data = .,
      slab = model)

# Meta Analysis: interaction
meta_re_interact <- 
  combined_results_attitude %>% 
  filter(regressor == "refugee_family:treat_parallel") %>%
  metafor::rma(measure="PCOR", 
      ti = t.stat,
      ni = N,
      mi = nparams,
      r2i = R2, 
      data = .,
      slab = model)

# Meta Analysis: total effect
meta_re_total <- 
  metafor::rma(measure="PCOR", 
              ti = t.stat,
              ni = N,
              mi = nparams,
              r2i = R2, 
      data = combined_results_attitude %>% filter(regressor == "refugee_T"),
      slab = model # labels
      ) 
```

### Plot

```{r}

plot_tab <- 
  tibble(estimate = c(meta_re_treat$b, meta_re_refguee$b, 
                      meta_re_interact$b, meta_re_total$b),
         se = c(meta_re_treat$se, meta_re_refguee$se, 
                meta_re_interact$se, meta_re_total$se), 
         regressor = c("refugee_family","treat_parallel",
                       "refugee_family:treat_parallel","refugee_T")) %>%
  mutate(
    regressor = fct_rev(
      recode_factor(
        regressor, 
        "refugee_family" = "refugee family",
        "treat_parallel" = "treated",
        "refugee_family:treat_parallel" = "treated x\nrefugee family",
        "refugee_T" = "net effect of treatment\non refugee familes")))
plot_tab %>%
  ggplot(aes(x = estimate, y=regressor)) + 
  geom_pointrange(aes(xmin = estimate + 1.96*se, xmax = estimate - 1.96*se), 
                  position = position_dodge(width = 0.6)) +
  geom_linerange(aes(xmin = estimate + 1.645*se, xmax = estimate - 1.645*se), size = 1.2,
                 position = position_dodge(width = 0.6)) +
  labs(x = "Partial Correlation Coefficient", 
       y = "Predictor",
       #caption = main_capt
       )  +
  guides(color = guide_legend(reverse = T),
         shape = guide_legend(reverse = T)) +
  scale_color_manual(values = get_colors("CUD Bright", 5))+
  theme_bw() + 
  geom_vline(xintercept = 0, lty = "dashed") +
  theme(#axis.title.y=element_blank(),
          axis.ticks.y = element_blank(),
          panel.grid.major.y=element_blank(),
          panel.grid.minor.y=element_blank(),
          plot.caption.position = "plot")

ggsave("Figures/Figure_2.png", width = 6, height = 2.3)
```

## Figure 3

Here we extract the relevant statistics from each regression, renaming
variables as needed as organizing the results into a tibble, using the
`prep_for_plot` function defined at the beginning of this file.

### Extract data

```{r}
combined_results_donate <- rbindlist(list(
  
  # Net effect of treatment on refugee families
  prep_for_plot(M.greek.total[[2]], 
                keep = "refugee_T",
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "1. Greece"),
  prep_for_plot(M.turk.total[[2]], 
                keep = "refugee_T", 
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "2. Turkey"),
  prep_for_plot(M.cyp.2021.total[[2]], 
                keep = "refugee_T",
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "3. Cyprus 2021"),
  
  # Coefficient estimates for treatment, refugee family, and their interaction
  prep_for_plot(M.greek[[2]], 
                keep = coef_renaming_vec,
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "1. Greece"),
  prep_for_plot(M.turk[[2]], 
                keep = coef_renaming_vec, 
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "2. Turkey"),
  prep_for_plot(M.cyp.2021[[2]], 
                keep = coef_renaming_vec,
                inner_CI_level = .9, R2 = T, nparams = T,
                model_name = "3. Cyprus 2021")
  ))

```

### Plot

```{r}
combined_results_donate %>% 
  mutate(
    Study = fct_rev(paste0( model, "\n(N = ", scales::comma(N), ")\n")),
    Outcome = fct_rev(dv),
    regressor = fct_rev(
      recode_factor(
        regressor, 
        "refugee_family" = "refugee family",
        "treat_parallel" = "treated",
        "refugee_family:treat_parallel" = "treated x\nrefugee family",
        "refugee_T" = "net effect of treatment\non refugee familes"))) %>%
  ggplot(aes(x = estimate, y=regressor, color = Study, shape =Study)) + 
  geom_pointrange(aes(xmin = low, xmax = high), 
                  position = position_dodge(width = 0.6)) +
  geom_linerange(aes(xmin = low_inner, xmax = high_inner), size = 1.2,
                 position = position_dodge(width = 0.6)) +
  labs(x = "Effect on Willingness to Donate to Refugee Relief (in SDs)", 
       y = "Predictor",
       )  +
  guides(color = guide_legend(reverse = T),
         shape = guide_legend(reverse = T)) +
  scale_color_manual(values = get_colors("CUD Bright", 3))+
  theme_bw() + 
  geom_vline(xintercept = 0, lty = "dashed") +
  theme(#axis.title.y=element_blank(),
          axis.ticks.y = element_blank(),
          panel.grid.major.y=element_blank(),
          panel.grid.minor.y=element_blank(),
          plot.caption.position = "plot")
ggsave("Figures/Figure_3.png", width = 6, height = 2.2)
```

## Figure 4

(This figure is an image of the newspaper ad, so no code is needed to
generate it. This section is merely a placeholder so that it's clear
nothing is missing.)

## Figure 5

### Extract Data

Here we extract the relevant statistics from each regression, renaming
variables as needed as organizing the results into a tibble, using the
`prep_for_plot` function defined at the beginning of this file.

```{r}
dat <- rbindlist(
  list(
    prep_for_plot(M.cyp.2022[[3]], 
                  keep = coef_renaming_vec,
                  inner_CI_level = .9,
                  model_name = 
                    '“refugee family” includes\n first generation refugees'),
    prep_for_plot(M.cyp.2022[[4]], 
                  keep = coef_renaming_vec,
                  inner_CI_level = .9,
                  model_name= 
                    '“refugee family” limited\nto refugee descendants'))) %>% 
  mutate(
    Outcome = fct_rev(dv),
    regressor = fct_rev(
      recode_factor(
        regressor, 
        "refugee_family" = "refugee family",
        "treat_parallel" = "treated",
        "refugee_family:treat_parallel" = "treated x\nrefugee family")))
```

### Plot

```{r}
dat %>% ggplot(aes(x = estimate, y=regressor)) + 
  geom_pointrange(aes(xmin = low, xmax = high), 
                  position = position_dodge(width = 0.6)) +
  geom_linerange(aes(xmin = low_inner, xmax = high_inner), size = 1.2,
                 position = position_dodge(width = 0.6)) +
  labs(x = "Effect on willingness to have name printed in newpaper (in SDs)",
       y = "Predictor")  +
  guides(color = guide_legend(reverse = T),
         shape = guide_legend(reverse = T)) +
  scale_color_manual(values = get_colors("CUD Bright", 3))+
  facet_wrap(~model) + 
  theme_bw() + 
  geom_vline(xintercept = 0, lty = "dashed") +
  theme(#axis.title.y=element_blank(),
          axis.ticks.y = element_blank(),
          panel.grid.major.y=element_blank(),
          panel.grid.minor.y=element_blank(),
          plot.caption.position = "plot")

ggsave("Figures/Figure_5.png", width = 6, height = 2)
```

## Figure 6

### Extract Data

```{r}
M.cyp.2022.split.by.gen <- c.2022 %>% 
  mutate(ref_status = case_when(first_gen_refugee == 1 ~ "firstgen",
                                refugee_family == 1 ~ "descendant",
                                T ~ "none")) %>%
  feglm(data = ., letter ~ treat_parallel + ..ctrls.2022, 
        split = ~ref_status)

plot_set_subs <- rbindlist(list(

  prep_for_plot(M.cyp.2022.split.by.gen[[2]], 
                keep = coef_renaming_vec,
                inner_CI_level = .9,
                model_name = "firstgen"),
  
  prep_for_plot(M.cyp.2022.split.by.gen[[1]], 
                keep = coef_renaming_vec,
                inner_CI_level = .9,
                model_name = "descendant"),
  
  prep_for_plot(M.cyp.2022.split.by.gen[[3]], 
                keep = coef_renaming_vec,
                inner_CI_level = .9,
                model_name = "none"))
  )
```

### Plot

```{r}
plot_set_subs %>% 
  mutate(subsample = model %>% 
           recode_factor(descendant = sprintf("refugee\ndescendant (n=%d)",
                                              nobs(M.cyp.2022.split.by.gen[[1]])),
                         none = sprintf("no refugees\nin family (n=%d)",
                                        nobs(M.cyp.2022.split.by.gen[[3]])),
                         firstgen = sprintf("first generation\nrefugee (n=%d)",
                                            nobs(M.cyp.2022.split.by.gen[[2]])))) %>%
  ggplot(aes(x = subsample, y=100*estimate)) + 
  geom_pointrange(aes(ymin = 100*low, ymax = 100*high), 
                  position = position_dodge(width = 0.6)) +
  geom_linerange(aes(ymin = 100*low_inner, ymax = 100*high_inner), size = 1.2,
                 position = position_dodge(width = 0.6)) + 
  scale_y_continuous(labels = scales::percent_format(scale = 1))+
  labs(y = "Effect of treatment on %\nwilling to sign newspaper ad", 
       x = "")  +
  theme_bw() + 
  geom_hline(yintercept = 0) +
  theme(axis.title.y=element_text(size = 10),
          axis.ticks.x = element_blank(),
          panel.grid.major.x=element_blank(),
          panel.grid.minor.x=element_blank())
ggsave("Figures/Figure_6.png", width = 6, height = 2.3)
```

# Online Appendix

## Section A - Replication of Greece Study

### Regressions

#### Prep data for Tables A1-2

```{r}
dinas.original <- sjlabelled::drop_labels(dinas)  %>% 
  drop_na(asiaminor, tr) %>% 
  select(tr_group, asiaminor, female, age, 
         primary, secondary, university,
         inc1000, inc3000, inc5000, 
         publicemp, privateemp, retired, selfemp, farmer,
         student, homemaker, unemployed,
         party_nd, party_syriza, party_pasok, party_kke, party_xa, rightwing, leftwing, prefecture)

dinas.replication <- sjlabelled::drop_labels(g.2022) %>% 
    drop_na(asiaminor, tr) %>% 
    select(tr_group, asiaminor, female, age, 
         primary, secondary, university,
         inc1000, inc3000, inc5000, 
         publicemp, privateemp, retired, selfemp, farmer,
         student, homemaker, unemployed, 
         party_syriza, party_pasok, party_kke, party_nd, party_xa, 
         rightwing, leftwing, prefecture)

dinas.comparison <- rbindlist(list(original = dinas.original, 
                                   replication = dinas.replication), 
                              fill = T, idcol = "sample") %>% 
  rename("Treated" = tr_group,"Female" = female,
         "Age" = age,
         "Asia Minor descendant" = asiaminor,
         "1000 or less" = inc1000,
         "1000 to 3000" = inc3000,
         "Above 3000" = inc5000,
         "higher" = university,
         "Public employee" = publicemp, 
         "Private employee" = privateemp, 
         "Pensioner" = retired, 
         "Self-employed" =selfemp,
         "Farmer" = farmer,
         "Student" = student, 
         "Homemaker" = homemaker,
         "Unemployed" = unemployed,
         "SYRIZA" = party_syriza,
         "PASOK" = party_pasok,
         "KKE" = party_kke,
         "New Democracy" = party_nd,
         "Golden Dawn" = party_xa,
         "Rightwing" = rightwing,
         "Leftwing" = leftwing) %>%
  mutate(Treated = +(Treated=="Treated"))
```

#### Table A1 - prefecture distribution

```{r}
datasummary_balance( ~ sample, 
                     data = dinas.comparison %>% select(sample, prefecture), 
                     output = "latex",
                     title = "Prefecture Distribution for Dinas et. al (2021) Greece Data and Replication \\label{tab:gr_prefectures }",
                     fmt = 2) %>%  save_kable(file = "Tables/GR Prefecture Table.tex")
```

#### Table A2 - summary statistics

```{r}
datasummary_balance( ~ sample, 
                     data = dinas.comparison %>% select(-prefecture), 
                     output = "latex",
                     title = "Summary Statistics for Dinas et. al (2021) Greece Data and Replication \\label{tab:gr_sumstats}",
                     fmt = 2) %>% 
  pack_rows("Education", 5, 7) %>%
  pack_rows("Income", 8, 10) %>%
  pack_rows("Occupation", 11, 18) %>%
  pack_rows("Party", 19, 23) %>%
  pack_rows("Party Ideology", 24, 25) %>%
  footnote(general = "The Greek party system shifted betewen the 2015 and 2019 elections, so not all parties appear in both surveys. Leftwing parties: SYRIZA, PASOK, KKE, MeRA25 (replication only), Course of Freedom (replication only). Rightwing parties: New Democracy, Golden Dawn, Greek Solution (replication only), ANEL (original only). Other parties: To Potami (original only) and the Union of Centrists (replication only).", threeparttable = T, footnote_as_chunk = T, general_title = "Note: ") %>% 
  save_kable(file = "Tables/GR Summary Stats Table.tex")

```

#### Table A3 - outcomes are principle components

```{r}

# Interaction effects
pc.1.a <- dinas %>% feglm(pc_behavior ~ asiaminor*tr, vcov = ~municipality)
pc.1.b <- g.2022 %>% feglm(pc_behavior ~ asiaminor*tr, vcov = ~municipality)

pc.2.a <- dinas %>% feglm(pc_behavior ~ asiaminor*tr + ..ctrls.dinas, vcov = ~municipality)
pc.2.b <- g.2022 %>% feglm(pc_behavior ~ asiaminor*tr + ..ctrls.dinas, vcov = ~municipality)

pc.3.a <- dinas %>% feglm(pc_attitude_full ~ asiaminor*tr, vcov = ~municipality)
pc.3.b <- g.2022 %>% feglm(pc_attitude_full ~ asiaminor*tr, vcov = ~municipality)

pc.4.a <- dinas %>% feglm(pc_attitude_full ~ asiaminor*tr + ..ctrls.dinas, vcov = ~municipality)
pc.4.b <- g.2022 %>% feglm(pc_attitude_full ~ asiaminor*tr + ..ctrls.dinas, vcov = ~municipality)

# total effects
pc.1.c <- dinas %>% feglm(pc_behavior ~ asiaminor + asia_T + 
              nonasia_T, vcov = ~municipality)
pc.1.d <- g.2022 %>% feglm(pc_behavior ~ asiaminor + asia_T + 
              nonasia_T, vcov = ~municipality)

pc.2.c <- dinas %>% feglm(pc_behavior ~ asiaminor + asia_T + 
              nonasia_T + ..ctrls.dinas, vcov = ~municipality)
pc.2.d <- g.2022 %>% feglm(pc_behavior ~ asiaminor + asia_T + 
              nonasia_T + ..ctrls.dinas, vcov = ~municipality)

pc.3.c <- dinas %>% feglm(pc_attitude_full ~ asiaminor + asia_T + 
              nonasia_T, vcov = ~municipality)
pc.3.d <- g.2022 %>% feglm(pc_attitude_full ~ asiaminor + asia_T + 
              nonasia_T, vcov = ~municipality)

pc.4.c <- dinas %>% feglm(pc_attitude_full ~ asiaminor + asia_T + 
              nonasia_T + ..ctrls.dinas, vcov = ~municipality)
pc.4.d <- g.2022 %>% feglm(pc_attitude_full ~ asiaminor + asia_T + 
              nonasia_T + ..ctrls.dinas, vcov = ~municipality)

# total effects table
pc.total.effects.tab <- etable(
  "Original (1)" = pc.1.c, "Replication (1)" = pc.1.d,
  "Original (2)" = pc.2.c, "Replication (2)" = pc.2.d,
  "Original (3)" = pc.3.c, "Replication (3)" = pc.3.d,
  "Original (4)" = pc.4.c, "Replication (4)" = pc.4.d,
  keep = "total", 
  drop.section = c("stats"), digits =2, 
  signif.code = c("***"=0.01, "**"=0.05, "*"=0.10))

# Main
etable("Original (1)" = pc.1.a, "Replication (1)" = pc.1.b,
       "Original (2)" = pc.2.a, "Replication (2)" = pc.2.b,
       "Original (3)" = pc.3.a, "Replication (3)" = pc.3.b,
       "Original (4)" = pc.4.a, "Replication (4)" = pc.4.b,
       group = list("_^Controls" = c("age")),
       extralines = list("total effect" = 
                           as.character(pc.total.effects.tab[3,]),
                         "on Asia Minor" = as.character(pc.total.effects.tab[4,])), 
       label = "tab:gr_reg_main",
       headers=list("Dataset:" = rep(c("Orig.", "Repl."),4)),
       title = "Comparison of Table 1 in Dinas, et. al (2021) to Replication", 
       style.tex = style.tex(yesNo = c("Y","N")),
       file = "Tables/GR Replication Table.tex", replace = T)
```

#### Tables A4-A5 - outcomes are means

```{r}

# Interaction effects
mean.1.a <- dinas %>% feglm(mean_behavior ~ asiaminor*tr, vcov = ~municipality)
mean.1.b <- g.2022 %>% feglm(mean_behavior ~ asiaminor*tr, vcov = ~municipality)

mean.2.a <- dinas %>% feglm(mean_behavior ~ asiaminor*tr + ..ctrls.dinas, vcov = ~municipality)
mean.2.b <- g.2022 %>% feglm(mean_behavior ~ asiaminor*tr + ..ctrls.dinas, vcov = ~municipality)

mean.3.a <- dinas %>% feglm(mean_attitude_full ~ asiaminor*tr, vcov = ~municipality)
mean.3.b <- g.2022 %>% feglm(mean_attitude_full ~ asiaminor*tr, vcov = ~municipality)

mean.4.a <- dinas %>% feglm(mean_attitude_full ~ asiaminor*tr + ..ctrls.dinas, vcov = ~municipality)
mean.4.b <- g.2022 %>% feglm(mean_attitude_full ~ asiaminor*tr + ..ctrls.dinas, vcov = ~municipality)

mean.5.a <- dinas %>% feglm(pc_attitude_core ~ asiaminor*tr, vcov = ~municipality)
mean.5.b <- g.2022 %>% feglm(pc_attitude_core ~ asiaminor*tr, vcov = ~municipality)

mean.6.a <- dinas %>% feglm(pc_attitude_core ~ asiaminor*tr + ..ctrls.dinas, vcov = ~municipality)
mean.6.b <- g.2022 %>% feglm(pc_attitude_core ~ asiaminor*tr + ..ctrls.dinas, vcov = ~municipality)

# total effects
mean.1.c <- dinas %>% feglm(mean_behavior ~ asiaminor + asia_T + 
              nonasia_T, vcov = ~municipality)
mean.1.d <- g.2022 %>% feglm(mean_behavior ~ asiaminor + asia_T + 
              nonasia_T, vcov = ~municipality)

mean.2.c <- dinas %>% feglm(mean_behavior ~ asiaminor + asia_T + 
              nonasia_T + ..ctrls.dinas, vcov = ~municipality)
mean.2.d <- g.2022 %>% feglm(mean_behavior ~ asiaminor + asia_T + 
              nonasia_T + ..ctrls.dinas, vcov = ~municipality)

mean.3.c <- dinas %>% feglm(mean_attitude_full ~ asiaminor + asia_T + 
              nonasia_T, vcov = ~municipality)
mean.3.d <- g.2022 %>% feglm(mean_attitude_full ~ asiaminor + asia_T + 
              nonasia_T, vcov = ~municipality)

mean.4.c <- dinas %>% feglm(mean_attitude_full ~ asiaminor + asia_T + 
              nonasia_T + ..ctrls.dinas, vcov = ~municipality)
mean.4.d <- g.2022 %>% feglm(mean_attitude_full ~ asiaminor + asia_T + 
              nonasia_T + ..ctrls.dinas, vcov = ~municipality)

mean.5.c <- dinas %>% feglm(pc_attitude_core ~ asiaminor + asia_T + 
              nonasia_T, vcov = ~municipality)
mean.5.d <- g.2022 %>% feglm(pc_attitude_core ~ asiaminor + asia_T + 
              nonasia_T, vcov = ~municipality)

mean.6.c <- dinas %>% feglm(pc_attitude_core ~ asiaminor + asia_T + 
              nonasia_T + ..ctrls.dinas, vcov = ~municipality)
mean.6.d <- g.2022 %>% feglm(pc_attitude_core ~ asiaminor + asia_T + 
              nonasia_T + ..ctrls.dinas, vcov = ~municipality)

total.effects.tab <- etable(
  "Original (1)" = mean.1.c, "Replication (1)" = mean.1.d,
  "Original (2)" = mean.2.c, "Replication (2)" = mean.2.d,
  "Original (3)" = mean.3.c, "Replication (3)" = mean.3.d,
  "Original (4)" = mean.4.c, "Replication (4)" = mean.4.d,
  "Original (5)" = mean.5.c, "Replication (5)" = mean.5.d,
  "Original (6)" = mean.6.c, "Replication (6)" = mean.6.d,
         keep = "total", drop.section = c("stats"), 
         signif.code = c("**"=0.01, "*"=0.05, "+"=0.10))

# Table A4 - Comparison of Table D6 Dinas to replication (part I)
## total effects table 

mean.total.effects.tab <- etable(
  "Original (1)" = mean.1.c, "Replication (1)" = mean.1.d,
  "Original (2)" = mean.2.c,"Replication (2)" =  mean.2.d,
  "Original (3)" = mean.3.c, "Replication (3)" = mean.3.d,
  "Original (4)" = mean.4.c,"Replication (4)" =  mean.4.d,
         keep = "total", drop.section = c("stats"),
  signif.code = c("***"=0.01, "**"=0.05, "*"=0.10))


## main table 
etable("Original (1)" = mean.1.a, "Replication (1)" = mean.1.b,
       "Original (2)" = mean.2.a, "Replication (2)" = mean.2.b,
       "Original (3)" = mean.3.a, "Replication (3)" = mean.3.b,
       "Original (4)" = mean.4.a, "Replication (4)" = mean.4.b,
       group = list("_^Controls" = c("age")),
       extralines = list("total effect on" = 
                           as.character(mean.total.effects.tab[3,]),
                          "Asia Minor" =as.character(mean.total.effects.tab[4,])), 
       label = "tab:gr_reg_D8_first",
       headers=list("Dataset:" = rep(c("Orig.", "Repl."),4)),
       title = "Comparison of Table D6 in Dinas, et. al (2021) to Replication (part 1)", 
       style.tex = style.tex(yesNo = c("Y","N")), 
       file = "Tables/GR Replication Table D6 first 8.tex", replace = T)

# Table A5 - Comparison of Table D6 Dinas to replication (part II)

## total effects table
mean.total.effects.tab.CONT <- etable(
  "Original (5)" = mean.5.c, "Replication (5)" = mean.5.d,
  "Original (6)" = mean.6.c, "Replication (6)" = mean.6.d,
         keep = "total", drop.section = c("stats"),
  signif.code = c("***"=0.01, "**"=0.05, "*"=0.10))

## main table
etable("Original (5)" = mean.5.a, "Replication (5)" = mean.5.b,
       "Original (6)" = mean.6.a, "Replication (6)" = mean.6.b,
       group = list("_^Controls" = c("age")),
       extralines = list("total effect on" = 
                           as.character(mean.total.effects.tab.CONT[3,]),
                          "Asia Minor" =as.character(mean.total.effects.tab.CONT[4,])), 
       label = "tab:gr_reg_D8_last",
       headers=list("Dataset:" = rep(c("Orig.", "Repl."),2)),
       title = "Comparison of Table D6 in Dinas, et. al (2021) to Replication (part 2)", 
       style.tex = style.tex(yesNo = c("Y","N")), 
       file = "Tables/GR Replication Table D6 last 4.tex", replace = T)
```

#### Table A6 - Weighting Replication Sample to Match Original

```{r}
# Interactions
wei <- g.2022 %>% feglm(c(pc_behavior, pc_attitude_full) ~ asiaminor*tr + 
                  sw0(..ctrls.dinas), vcov = ~municipality, weights = ~weights)

# total effects
wei.total <- g.2022 %>% 
  feglm(c(pc_behavior, pc_attitude_full) ~ asiaminor + 
                  asia_T + nonasia_T + sw0(..ctrls.dinas), 
                vcov = ~municipality, weights = ~weights)

# total effects table
wei.total.effects.tab <- etable(wei.total,
         keep = "total", drop.section = c("stats"),
  signif.code = c("***"=0.01, "**"=0.05, "*"=0.10))

# Main table
etable(wei,
       group = list("_^Controls" = c("age")),
       extralines = list("total effect on" = 
                           as.character(wei.total.effects.tab[3,]),
                          "Asia Minor" =as.character(wei.total.effects.tab[4,])), 
       label = "tab:gr_reg_wei",
       title = "Main Models Weighting Replication Sample to Match Original", 
       style.tex = style.tex(yesNo = c("Y","N")), 
       file = "Tables/GR Replication Weighted.tex", replace = T)
```

#### Table A7 - original data split by party ideology

```{r}

# interaction effects
ideo <- dinas %>% mutate(Leftwing = case_when(leftwing==0 ~ "No",
                                                leftwing==1 ~ "Yes")) %>%
  feglm(c(pc_behavior, pc_attitude_full) ~ asiaminor*tr + 
          csw0(..ctrls.dinas), vcov = ~municipality, split = ~Leftwing) 

# total effects
total.ideo <- dinas %>% mutate(Leftwing = case_when(leftwing==0 ~ "No",
                                                leftwing==1 ~ "Yes")) %>%
  feglm(c(pc_behavior, pc_attitude_full) ~ asiaminor + 
                  asia_T + nonasia_T + csw0(..ctrls.dinas), 
                vcov = ~municipality, split = ~Leftwing)

# total effects table
ideo.total.effects.tab <-  total.ideo %>% 
  etable(keep = "total", signif.code = c("***"=0.01, "**"=0.05, "*"=0.10))

# main table 
ideo %>% 
  etable(group = list("_^Standard Controls" = c("age")),
         extralines = list("total effect" = as.character(ideo.total.effects.tab[4,]),
                           "on Asia Minor" = as.character(ideo.total.effects.tab[5,])),
         label = "tab:gr_reg_ideo_orig",
         title = "Table 1 in Dinas, et. al (2021) split by party ideology", 
         style.tex = style.tex(yesNo = c("Y","N")),
         file = "Tables/GR Original Ideology Table.tex", 
         signif.code = c("***"=0.01, "**"=0.05, "*"=0.10),
         replace = T)

```

#### Table A8 - replication data split by party ideology

```{r}

# Interaction effects
rep.ideo <- g.2022 %>% mutate(Leftwing = case_when(leftwing==0 ~ "No",
                                                leftwing==1 ~ "Yes")) %>%
  feglm(c(pc_behavior, pc_attitude_full) ~ asiaminor*tr + 
          csw0(..ctrls.dinas), vcov = ~municipality, split = ~Leftwing)

# total Effects
total.rep.ideo <- g.2022 %>% mutate(Leftwing = case_when(leftwing==0 ~ "No",
                                                leftwing==1 ~ "Yes")) %>%
  feglm(c(pc_behavior, pc_attitude_full) ~ asiaminor + 
                  asia_T + nonasia_T + csw0(..ctrls.dinas), 
                vcov = ~municipality, split = ~Leftwing)

# total effects table
rep.ideo.total.effects.table <- total.rep.ideo %>% 
  etable(keep = "total", signif.code = c("***"=0.01, "**"=0.05, "*"=0.10))

# Main table
rep.ideo %>%
  etable(group = list("_^Standard Controls" = c("age")),
         extralines = list("total effect" = as.character(rep.ideo.total.effects.table[4,]),
                           "on Asia Minor" = as.character(rep.ideo.total.effects.table[5,])),
         label = "tab:gr_reg_ideo_repl",
         title = "Regressions on replication data split by party ideology", 
         style.tex = style.tex(yesNo = c("Y","N")),
         file = "Tables/GR Replication Ideology Table.tex", replace = T)

```

## Section E - Descriptive Statistics

### Turkey

#### Table E1

```{r}
x <- t.2021 %>%
  mutate(treated = if_else(treat_parallel==1,
                             "treated", 
                             "control"),
         refugee_family = if_else(refugee_family==1, 
                                 "refugee family", 
                                 "non-refugee")) %>% 
  select(all_of(ctrls.turk), district, party, religiosity,
         treated, refugee_family) %>% 
  rename_with(~ gsub("_", " ", .x, fixed = TRUE)) %>%
  as.data.frame()

# Summary Statistics
sumstats <- datasummary_balance( ~ 1, 
                                 data = x, 
                                 fmt = 2, 
                                 notes = paste0("Note: N=", nrow(x)),
                                 title = "Turkey 2021 Descriptive Statistics\\label{tab:turk_desc}",
                          output = "latex")

# Table E1 
print(sumstats,
      file = "Tables/Turkey Summary Only.tex")
```

#### Check Balance

```{r}
y <- x %>% select(-district, - party, -religiosity ) %>%
  fastDummies::dummy_cols("parent lang", remove_selected_columns = T) %>% 
  rename_with(~ gsub("_", ": ", .x, fixed = TRUE))


# Balance Table by Treatment Condition
baltab.tc <- datasummary_balance( ~ treated,
                          data = y %>% mutate(`refugee family` = 1*(`refugee family`=="refugee family")),
                          fmt = 2, 
                          title = "Turkey 2021 Balance Table by Treatment Condition\\label{tab:turk_bal_condition}", 
                          output = "latex"
                          )

# F-test
ftest.reg <- t.2021 %>% 
  lm(data = ., xpd(treat_parallel ~ ..ctrls.turk))
summary(ftest.reg)

ftest.reg <- t.2021 %>% 
  lm(data = ., xpd(treat_parallel ~ party_original + religiosity_cat))
summary(ftest.reg)

z <- y %>% 
  rename(heritage = `refugee family`) %>% 
  mutate(treated = 1*(treated=="treated"))

# Balance Table by Refugee Heritage
baltab.rf <- datasummary_balance( ~ heritage,
                          data = z,
                          fmt = 2, 
                          ##dinm_statistic = "p.value",
                          title = "Turkey 2021 Balance Table by Refugee Family Status\\label{tab:turk_bal_heritage}", 
                          output = "latex"
                          )

# Balance Tables (available upon request)
print(sumstats, "\n\n", baltab.tc, "\n\n",  baltab.rf,
      file = "Tables/Turkey Summary.tex")
```

#### Matching

```{r}
# filter out NAs to comply with MatchIt
pre_matched_data <- t.2021 %>%  
  select(all_of(ctrls.turk),
        id,
        -district,
        refugee_family,
        treat_parallel) %>%
  drop_na() 


# means of binary variables left unstandardized
bal.tab(pre_matched_data %>% select(-id),
        treat = pre_matched_data$refugee_family,
        thresholds = c(m = .1),
        binary = "std")


match.turk <- 
  matchit(refugee_family ~ age + male + freq_contact + estimate_Syrian_pct  +
            college,
                  data = pre_matched_data,
                  cutpoints = list(
                    age = c(35, 48)),
                  estimand = "ATE", method = "cem", distance = "glm")

# Check balance across refugee heritage
match.baltab.rf <- bal.tab(match.turk, 
        addl = pre_matched_data %>% select(-id),
        thresholds = c(m = .1), 
        method = "matching",
        un =T)

# create new dataset with weights
matched_data <- pre_matched_data %>% mutate(weights = match.turk$weights)

# Check balance across treatment conditions
match.baltab.tc <-bal.tab(treat_parallel ~ . - id - weights, 
        data = matched_data,
        weights = "weights",
        method = "matching",
        s.d.denom = "pooled",
        thresholds = c(m = .1),
        un = T)
```

#### Figure E1

```{r}

# Make variables names pretty for plot
renaming.df <- var.names(match.baltab.rf, type = "df", minimal = F)
renaming.df$new <- renaming.df$old %>% 
  str_replace_all("parent_lang_", "parent_lang: ") %>%
  str_replace_all("\\_", " ") 
renaming.df <- renaming.df %>% add_row(old = "treat_parallel", new = "treated")
renaming.df <- renaming.df %>% add_row(old = "refugee_family", new = "refugee family")

# Love plot for treatment condition
left <- love.plot(match.baltab.tc,
          s.d.denom = "pooled", stars = "std", thresholds = 0.1, 
          var.names = renaming.df, 
          var.order = "alphabetical",
          sample.names = c("Original", "Matched"),
          shapes = c("circle","triangle"), 
          colors = c("gray20", "gray60")) + labs(subtitle = "by treatment condition",)

# Love plot for refugee heritage
right <- love.plot(match.baltab.rf, 
          s.d.denom = "pooled", stars = "std", thresholds = 0.1, 
          var.names = renaming.df,
          var.order = "alphabetical",
          sample.names = c("Original", "Matched"),
          shapes = c("circle","triangle"), 
          colors = c("gray20", "gray60")) + labs(subtitle = "by refugee heritage",)

left+right + plot_layout(guides = 'collect') &
  theme(legend.position='bottom')

# Figure E1
ggsave("Figures/Turkey_love_plot.png", width = 6, height = 8)

# Add weights column to dataset
t.2021 <- matched_data %>% select(id, weights) %>% 
  full_join(t.2021, by = "id")
```

### Cyprus 2018

#### Table E2

```{r}
x <- c.2018 %>%
  mutate(treated = if_else(treat_parallel==1,
                             "treated", 
                             "control"),
         refugee_family = if_else(refugee_family==1, 
                                 "refugee family", 
                                 "non-refugee")) %>% 
  select(age, male, district, married, parent, 
         unemployed, lived_abroad, voted, church_freq, class, education,
         treated, refugee_family) %>% 
  rename_with(~ gsub("_", " ", .x, fixed = TRUE)) %>%
  as.data.frame()


sumstats <- datasummary_balance( ~ 1, 
                                 data = x, 
                                 fmt = 2,
                                 notes = paste0("Note: N=", nrow(x)),
                                 title = "Cyprus 2018 Descriptive Statistics\\label{tab:cyp18_desc}",
                          output = "latex")

print(sumstats,
      file = "Tables/Cyprus 2018 Summary Only.tex")
```

#### Check Balance

```{r}
# F-test for treatment
ftest.reg <- c.2018 %>% lm(data = ., xpd(treat_parallel ~ ..ctrls.2018.alt))
summary(ftest.reg)

# F-test for heritage
ftest.reg <- c.2018 %>% lm(data = ., xpd(refugee_family ~ ..ctrls.2018.alt))
summary(ftest.reg)

y <- x %>% select(-district) %>%
  rename_with(~ gsub("_", ": ", .x, fixed = TRUE))

# Balance Table by Treatment Condition
baltab.tc <- datasummary_balance( ~ treated,
                          data = y %>% mutate(`refugee family` = 1*(`refugee family`=="refugee family")),
                          fmt = 2, 
                          title = "Cyprus 2018 Balance Table by Treatment Condition\\label{tab:cyp18_bal_condition}", 
                          output = "latex")

z <- y %>% 
  rename(heritage = `refugee family`) %>% 
  mutate(treated = 1*(treated=="treated"))


# Balance Table by Refugee Heritage
baltab.rf <- datasummary_balance( ~ heritage,
                          data = z,
                          fmt = 2, 
                          title = "Cyprus 2018 Balance Table by Refugee Family Status\\label{tab:cyp18_bal_heritage}",
                          output = "latex")

# Balance Tables (available upon request)
print(sumstats, "\n\n", baltab.tc, "\n\n",  baltab.rf,
      file = "Tables/Cyprus 2018 Summary.tex")
```

#### Matching

```{r}
# filter out NAs to comply with MatchIt
pre_matched_data <- c.2018 %>%  
  select(all_of(ctrls.2018.alt),
         -district,
         id,
         refugee_family,
         treat_parallel) %>%
  drop_na() 


bal.tab(pre_matched_data %>% select(-id),
        treat = pre_matched_data$refugee_family,
        thresholds = c(m = .1), binary = "std")

# Match
(match.2018 <- matchit(refugee_family ~ age + class + church_freq,
                       #+ estimate_Syrian_N
                       data = pre_matched_data,
                       cutpoints = list(age = c(30, 45, 65)),
                       estimand = "ATE", method = "cem", distance = "glm"))

# Check balance across refugee heritage
match.baltab.rf <- bal.tab(match.2018, 
                           addl = pre_matched_data %>% select(-id),
                           thresholds = c(m = .1), 
                           method = "matching",
                           binary = "std",
                           un =T)

# create new dataset with weights
matched_data <- pre_matched_data %>% mutate(weights = match.2018$weights)

# Check balance across treatment conditions
match.baltab.tc <-bal.tab(treat_parallel ~ . - id - weights, 
                           data = matched_data,
                           weights = "weights",
                           binary = "std",
                           method = "matching",
                           s.d.denom = "pooled",
                           thresholds = c(m = .1),
                           un = T)
```

#### Figure E2

```{r}
# Make variables names pretty for plot
renaming.df <- var.names(match.baltab.rf, type = "df", minimal = F)
renaming.df$new <- renaming.df$old %>% 
  str_replace_all("freq_contact_", "freq contact: ") %>%
  str_replace_all("asylum_", "asylum: ") %>%
  str_replace_all("income_", "income: ") %>%
  str_replace_all("\\_", " ") 
renaming.df <- renaming.df %>% add_row(old = "treat_parallel", new = "treated")
renaming.df <- renaming.df %>% add_row(old = "refugee_family", new = "refugee family")

# Love plot for treatment condition
left <- love.plot(match.baltab.tc,
                  s.d.denom = "pooled", stars = "std", thresholds = 0.1, 
                  var.names = renaming.df, 
                  var.order = "alphabetical",
                  sample.names = c("Original", "Matched"),
                  shapes = c("circle","triangle"), 
                  colors = c("gray20", "gray60")) + labs(subtitle = "by treatment condition",)

# Love plot for refugee heritage
right <- love.plot(match.baltab.rf, 
                   s.d.denom = "pooled", stars = "std", thresholds = 0.1, 
                   var.names = renaming.df,
                   var.order = "alphabetical",
                   sample.names = c("Original", "Matched"),
                   shapes = c("circle","triangle"), 
                   colors = c("gray20", "gray60")) + labs(subtitle = "by refugee heritage")

left+right + plot_layout(guides = 'collect') &
  theme(legend.position='bottom')

# Figure E2
ggsave("Figures/Cyprus_2018_love_plot.png", width = 7.5, height = 4)

# Add weights column to dataset
c.2018 <- matched_data %>% select(id, weights) %>% 
  full_join(c.2018, by = "id")
```

### Cyprus 2021

#### Table E3

```{r}
x <- c.2021 %>%
  mutate(treated = if_else(treat_parallel==1,
                             "treated", 
                             "control"),
         refugee_family = if_else(refugee_family==1, 
                                 "refugee family", 
                                 "non-refugee")) %>% 
  select(all_of(ctrls.2021), asylum, treated, refugee_family) %>% 
  select(-asylum_all, -asylum_none) %>%
  rename_with(~ gsub("_", " ", .x, fixed = TRUE)) %>%
  as.data.frame()


sumstats <- datasummary_balance( ~ 1, 
                                 data = x, 
                                 fmt = 2,
                                 notes = paste0("Note: N=", nrow(x)),
                                 title = "Cyprus 2021 Descriptive Statistics\\label{tab:cyp21_desc}",
                          output = "latex")

print(sumstats, 
      file = "Tables/Cyprus 2021 Summary Only.tex")
```

#### Check Balance

```{r}
# F-test
ftest.reg <- c.2021 %>% lm(data = ., xpd(treat_parallel ~ ..ctrls.2021))
summary(ftest.reg)

y <- x %>%
  fastDummies::dummy_cols("income", remove_selected_columns = T) %>%
  fastDummies::dummy_cols("freq contact", remove_selected_columns = T) %>% 
  fastDummies::dummy_cols("landsea treatment", remove_selected_columns = T) %>%   fastDummies::dummy_cols("asylum", remove_selected_columns = T) %>%
  rename_with(~ gsub("_", ": ", .x, fixed = TRUE))

# Balance Table by Treatment Condition
baltab.tc <- datasummary_balance( ~ treated,
                          data = y %>% mutate(`refugee family` = 1*(`refugee family`=="refugee family")),
                          fmt = 2, 
                          title = "Cyprus 2021 Balance Table by Treatment Condition\\label{tab:cyp21_bal_condition}", 
                          output = "latex")

z <- y %>% 
  rename(heritage = `refugee family`) %>% 
  mutate(treated = 1*(treated=="treated"))

# Balance Table by Refugee Heritage
baltab.rf <- datasummary_balance( ~ heritage,
                          data = z,
                          fmt = 2, 
                          title = "Cyprus 2021 Balance Table by Refugee Family Status\\label{tab:cyp21_bal_heritage}", 
                          output = "latex")

# Balance Tables (available upon request)
print(sumstats, "\n\n", baltab.tc, "\n\n",  baltab.rf,
      file = "Tables/Cyprus 2021 Summary.tex")
```

#### Matching

```{r}
# filter out NAs to comply with MatchIt
pre_matched_data <- c.2021 %>%  
  select(all_of(ctrls.2021),
        id,
        refugee_family,
        treat_parallel) %>%
  drop_na() 

bal.tab(pre_matched_data %>% select(-id),
        treat = pre_matched_data$refugee_family,
        thresholds = c(m = .1), binary = "std")

# Match
(match.2021 <- matchit(refugee_family ~ age + voted,
                       data = pre_matched_data,
                  cutpoints = list(age = c(30, 45, 65)),
                  estimand = "ATE", method = "cem", distance = "glm"))

# Check balance across refugee heritage
match.baltab.rf <- bal.tab(match.2021, 
        addl = pre_matched_data %>% select(-id),
        thresholds = c(m = .1), 
        method = "matching",
        binary = "std",
        un =T)

# create new dataset with weights
matched_data <- pre_matched_data %>% mutate(weights = match.2021$weights)

# Check balance across treatment conditions
match.baltab.tc <-bal.tab(treat_parallel ~ . - id - weights, 
        data = matched_data,
        weights = "weights",
        binary = "std",
        method = "matching",
        s.d.denom = "pooled",
        thresholds = c(m = .1),
        un = T)
```

#### Figure E3

```{r}
# Make variables names pretty for plot
renaming.df <- var.names(match.baltab.rf, type = "df", minimal = F)
renaming.df$new <- renaming.df$old %>% 
  str_replace_all("freq_contact_", "freq contact: ") %>%
  str_replace_all("asylum_", "asylum: ") %>%
  str_replace_all("income_", "income: ") %>%
  str_replace_all("\\_", " ") 
renaming.df <- renaming.df %>% add_row(old = "treat_parallel", new = "treated")
renaming.df <- renaming.df %>% add_row(old = "refugee_family", new = "refugee family")

# Love plot for treatment condition
left <- love.plot(match.baltab.tc,
          s.d.denom = "pooled", stars = "std", thresholds = 0.1, 
          var.names = renaming.df, 
          var.order = "alphabetical",
          sample.names = c("Original", "Matched"),
          shapes = c("circle","triangle"), 
          colors = c("gray20", "gray60")) + labs(subtitle = "by treatment condition",)

# Love plot for refugee heritage
right <- love.plot(match.baltab.rf, 
          s.d.denom = "pooled", stars = "std", thresholds = 0.1, 
          var.names = renaming.df,
          var.order = "alphabetical",
          sample.names = c("Original", "Matched"),
          shapes = c("circle","triangle"), 
          colors = c("gray20", "gray60")) + labs(subtitle = "by refugee heritage",)
left+right + plot_layout(guides = 'collect') &
  theme(legend.position='bottom')

ggsave("Figures/Cyprus_2021_love_plot.png", width = 7.5, height = 9)

# Add weights column to dataset
c.2021 <- matched_data %>% select(id, weights) %>% 
  full_join(c.2021, by = "id")
```

### Cyprus 2022

#### Table E4

```{r}
x <- c.2022 %>%
  mutate(treated = if_else(treat_parallel==1,
                             "treated", 
                             "control"),
         refugee_family = if_else(refugee_family==1, 
                                 "refugee family", 
                                 "non-refugee")) %>% 
  select(all_of(ctrls.2022), treated, refugee_family) %>% 
  rename_with(~ gsub("_", " ", .x, fixed = TRUE)) %>%
  rename_with(~ gsub("yearround", "year-round", .x, fixed = TRUE)) %>%
  rename_with(~ gsub("hh", "household", .x, fixed = TRUE)) %>%
  as.data.frame()

# Summary Statistics
sumstats <- datasummary_balance( ~ 1, 
                                 data = x, 
                                 fmt = 2,
                                 notes = paste0("Note: N=", nrow(x)),
                                 title = "Cyprus 2022 Descriptive Statistics\\label{tab:cyp22_desc}", 
                          output = "latex"
                          )

print(sumstats,
      file = "Tables/Cyprus 2022 Summary Only.tex")
```

#### Check Balance

```{r}
# F-test
ftest.reg <- c.2022 %>% lm(data = ., xpd(treat_parallel ~ ..ctrls.2022))
summary(ftest.reg)

# # F-test with PAP variables
# ftest.reg <- c.2022 %>% lm(data = ., xpd(treat_parallel ~ ..ctrls.2022.pap))
# summary(ftest.reg)

y <- x %>%
  fastDummies::dummy_cols("job type", remove_selected_columns = T) %>% 
  fastDummies::dummy_cols("income", remove_selected_columns = T) %>% 
  rename_with(~ gsub("_", ": ", .x, fixed = TRUE))

# Balance Table by Treatment Condition
baltab.tc <- datasummary_balance( ~ treated,
                          data = y %>% mutate(`refugee family` = 1*(`refugee family`=="refugee family")),
                          fmt = 2, 
                          title = "Cyprus 2022 Balance Table by Treatment Condition\\label{tab:cyp22_bal_condition}", 
                          output = "latex"
                          )

z <- y %>% 
  rename(heritage = `refugee family`) %>% 
  mutate(treated = 1*(treated=="treated"))

# Balance Table by Refugee Heritage
baltab.rf <- datasummary_balance( ~ heritage,
                          data = z,
                          fmt = 2, 
                          title = "Cyprus 2022 Balance Table by Refugee Family Status\\label{tab:cyp22_bal_heritage}", 
                          output = "latex"
                          )
# Balance Tables (available upon request)
print(sumstats, "\n\n", baltab.tc, "\n\n",  baltab.rf,
      file = "Tables/Cyprus 2022 Summary.tex")
```

#### Matching

```{r}
# filter out NAs to comply with MatchIt
pre_matched_data <- c.2022 %>%  
  select(all_of(ctrls.2022),
        refugee_family,
        treat_parallel,
        -violence_family,
        id) %>%
  drop_na() 


bal.tab(pre_matched_data %>% select(-id),
        treat = pre_matched_data$refugee_family,
        thresholds = c(m = .1),
        binary = "std")



match.2022 <- matchit(refugee_family ~ age + heard_of_pournara + 
                         job_type_Wage_labor, 
                       data = pre_matched_data %>% 
                         mutate(job_type_Wage_labor = job_type=="Wage labor",
                                ),
                  cutpoints = list(age = c(18, 60),
                                   freq_see_asylum = c(1,5)
                                   ), 
                  groups = list(income = list(c("0-10k",
                                                  "11-20k",
                                                  "21-30k",
                                                  "41k or more",
                                                  "refused"),
                                                  c("Nonresponse"))),
                  estimand = "ATE", method = "cem", distance = "glm")

# Check balance across refugee heritage
match.baltab.rf <- bal.tab(match.2022, 
        addl = pre_matched_data %>% select(-id),
        thresholds = c(m = .1), 
        method = "matching",
        un =T)

match.baltab.rf

# create new dataset with weights
matched_data <- pre_matched_data %>% mutate(weights = match.2022$weights)

# Check balance across treatment conditions
(match.baltab.tc <-bal.tab(treat_parallel ~ . -id - weights, 
        data = matched_data, 
        weights = "weights",
        method = "matching",
        s.d.denom = "pooled",
        thresholds = c(m = .1),
        un = T))
```

#### Figure E4

```{r}
# Make variables names pretty for plot
renaming.df <- var.names(match.baltab.rf, type = "df", minimal = F)
renaming.df$new <- renaming.df$old %>% 
  str_replace_all("hh", "household") %>%
  str_replace_all("income_", "income: ") %>%
  
  str_replace_all("\\_", " ") 
renaming.df <- renaming.df %>% add_row(old = "treat_parallel", new = "treated")
renaming.df <- renaming.df %>% add_row(old = "refugee_family", new = "refugee family")

# Love plot for treatment condition
left <- love.plot(match.baltab.tc,
          s.d.denom = "pooled", stars = "std", thresholds = 0.1, 
          var.names = renaming.df, 
          var.order = "alphabetical",
          sample.names = c("Original", "Matched"),
          shapes = c("circle","triangle"), 
          colors = c("gray20", "gray60")) + labs(subtitle = "by treatment condition",)

# Love plot for refugee heritage
right <- love.plot(match.baltab.rf, 
          s.d.denom = "pooled", stars = "std", thresholds = 0.1, 
          var.names = renaming.df,
          var.order = "alphabetical",
          sample.names = c("Original", "Matched"),
          shapes = c("circle","triangle"), 
          colors = c("gray20", "gray60")) + labs(subtitle = "by refugee heritage",)
left+right + plot_layout(guides = 'collect') &
  theme(legend.position='bottom')

ggsave("Figures/Cyprus_2022_love_plot.png", width = 7.5, height = 8)

# Add weights column to data
c.2022 <- matched_data %>% select(id, weights) %>% 
  full_join(c.2022, by = "id")
```

#### Matching (no first gen)

```{r}
# F-test
ftest.reg <- c.2022.nome %>% lm(data = ., xpd(treat_parallel ~ ..ctrls.2022 ))
summary(ftest.reg)

# filter out NAs to comply with MatchIt
pre_matched_data <- c.2022.nome %>%  
  select(all_of(ctrls.2022),
        id,
        -violence_family,
        refugee_family,
        treat_parallel) %>%
  drop_na()


bal.tab(pre_matched_data %>% select(-id),
        treat = pre_matched_data$refugee_family,
        thresholds = c(m = .1),
        binary = "std")

# Match
(match.2022.nome <- matchit(refugee_family ~ age + freq_see_asylum + college + heard_of_pournara + job_type_Nonresponse + job_type_Wage_labor, 
                       data = pre_matched_data %>% 
                         mutate(job_type_Wage_labor = job_type=="Wage labor",
                                job_type_Nonresponse = job_type=="Nonresponse"),
                  cutpoints = list(age = c(18, 48),
                                   freq_see_asylum = c(1,5)
                                   ),
                  estimand = "ATE", method = "cem", distance = "glm"))

# Check balance across refugee heritage
match.baltab.rf <- bal.tab(match.2022.nome, 
        addl = pre_matched_data %>% select(-id),
        thresholds = c(m = .1), 
        method = "matching", binary = "std",
        un =T)

match.baltab.rf

# create new dataset with weights
matched_data <- pre_matched_data %>% mutate(weights = match.2022.nome$weights)

# Check balance across treatment conditions
match.baltab.tc <-bal.tab(treat_parallel ~ . -id - weights, 
        data = matched_data,
        weights = matched_data$weights, 
        method = "matching",
        s.d.denom = "pooled",
        thresholds = c(m = .1),
        un = T)
match.baltab.tc
```

#### Figure E5

```{r}
# Make variables names pretty for plot
renaming.df <- var.names(match.baltab.rf, type = "df", minimal = F)
renaming.df$new <- renaming.df$old %>% 
  str_replace_all("hh", "household") %>%
  str_replace_all("income_", "income: ") %>%
  str_replace_all("\\_", " ") 
renaming.df <- renaming.df %>% add_row(old = "treat_parallel", new = "treated")
renaming.df <- renaming.df %>% add_row(old = "refugee_family", new = "refugee family")

# Love plot for treatment condition
left <- love.plot(match.baltab.tc,
          s.d.denom = "pooled", stars = "std", thresholds = 0.1, 
          var.names = renaming.df, 
          var.order = "alphabetical",
          sample.names = c("Original", "Matched"),
          shapes = c("circle","triangle"), 
          colors = c("gray20", "gray60")) + labs(subtitle = "by treatment condition",)

# Love plot for refugee heritage
right <- love.plot(match.baltab.rf, 
          s.d.denom = "pooled", stars = "std", thresholds = 0.1, 
          var.names = renaming.df, 
          var.order = "alphabetical",
          sample.names = c("Original", "Matched"),
          shapes = c("circle","triangle"), 
          colors = c("gray20", "gray60")) + labs(subtitle = "by refugee heritage",)
left+right + plot_layout(guides = 'collect') &
  theme(legend.position='bottom')

ggsave("Figures/Cyprus_2022_no_first_gen_love_plot.png", width = 7.5, height = 8)

#c.2022.nome.matched <- matched_data
c.2022.nome <- matched_data %>% select(id, weights) %>% 
  full_join(c.2022.nome, by = "id")
```

## Section F - Results

### Section F.1 Main Results

```{r}
# Table F1
etable(M.greek, 
       tex = T, 
       se.below = F,
       label = "tab:main_plot_greece",
       title = "Table for Figures 1 and 3 (Greece)", 
       file = "Tables/Greece Plot Table.tex", replace = T)

# Table F2
etable(M.turk, 
       tex = T, 
       se.below = F,
       label = "tab:main_plot_turk",
       title = "Table for Figures 1 and 3 (Turkey)", 
       file = "Tables/Turkey Plot Table.tex", replace = T)

# Table F3
etable(M.cyp.2018, 
       tex = T, 
       se.below = F,
       label = "tab:main_plot_cyp18",
       title = "Table for Figure 1 (Cyprus 2018)", 
       file = "Tables/Cyprus 2018 Plot Table.tex", replace = T)

# Table F4
etable(M.cyp.2021, 
       tex = T, 
       se.below = F,
       label = "tab:main_plot_cyp21",
       title = "Table for Figures 1 and 3 (Cyprus 2021)", 
       file = "Tables/Cyprus 2021 Plot Table.tex", replace = T)

# Table F5
etable(M.cyp.2022, 
       tex = T, 
       se.below = F,
       label = "tab:main_plot_cyp22",
       title = "Table for Figures 1 and 5 (Cyprus 2022)", 
       file = "Tables/Cyprus 2022 Plot Table.tex", replace = T,
       extralines = list("First Gen. Refugees" = c("included", "excluded", "included", "excluded"))
       )

# Table F6
etable(M.cyp.2022.split.by.gen, 
       tex = T, 
       se.below = F,
       label = "tab:main_letter_split_status",
       title = "Table for Figure 6 (Cyprus 2022)", 
       file = "Tables/Main Letter Split Table Status.tex", replace = T)

# Table F7
M.cyp.2022.split.by.gen.NONrefugee <- c.2022 %>%
  filter(refugee_family==0) %>%
  mutate(generation = case_when(age > 48 ~ "older",
                                T ~ "younger")) %>%
  feglm(data = ., letter ~ treat_parallel + ..ctrls.2022,
        split = ~generation)

etable(M.cyp.2022.split.by.gen.NONrefugee, 
       tex = T, 
       se.below = F,
       label = "tab:main_letter_split_gen",
       title = "Letter outcome subset by generation among *non-refugee* families (Cyprus 2022)", 
       file = "Tables/Main Letter Split Table Gen.tex", replace = T)

```

### Section F.2 Robustness Checks

#### Turkey

##### Regressions

```{r turk robust}

# Main
regs.turk <- t.2021 %>% 
  feglm(data = ., 
        c(concern, admissions, permits, 
          therm_syrian, donate, letter, attitude_mean) ~ 
          refugee_family*treat_parallel + ..ctrls.turk)

# No controls
regs.turk.no.ctrls <- t.2021 %>%
  feglm(data = .,
        c(concern, admissions, permits, 
          therm_syrian, donate, letter, attitude_mean) ~
          refugee_family*treat_parallel)

# Alternatives for Binary Outcomes
regs.turk.log <- t.2021 %>% 
  feglm(data = ., c(donation_amount, donation_amount_log) ~ 
          refugee_family*treat_parallel + ..ctrls.turk)

regs.turk.logit <- t.2021 %>% 
  feglm(data = ., 
        c(donate, letter) ~ 
          refugee_family*treat_parallel + ..ctrls.turk, 
        family = binomial())

# Preregistered set of controls 
regs.turk.pap <- t.2021 %>% 
  feglm(data = ., 
        c(concern, admissions, permits, 
          therm_syrian, donate, letter, attitude_mean) ~ 
          refugee_family*treat_parallel + ..ctrls.turk.pap)

# Interactions with all controls
regs.turk.interact <- t.2021 %>% 
  feglm(data = ., 
        c(concern, admissions, permits, 
          therm_syrian, donate, letter, attitude_mean) ~ 
          refugee_family*treat_parallel + treat_parallel*(..ctrls.turk))
  
# Matched Data
regs.turk.match <- t.2021 %>% 
  feglm(data = ., 
        c(concern, admissions, permits, 
          therm_syrian, donate, letter, attitude_mean) ~ 
          refugee_family*treat_parallel + ..ctrls.turk,
        weights = ~ weights)

```

##### Tables

```{r}

# Table F8 - Main regression
tab.turk <- etable(regs.turk, tex = T, se.below = se_setting,
       keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"), 
       label = "tab:turk_reg",
       title = "All outcomes using OLS regression (Turkey)", 
       file = "Tables/Turkey Regressions.tex", replace = T)

# Table F9 - No controls
tab.turk.no.ctrls <- etable(regs.turk.no.ctrls, tex = T,
       keep = c("^treated$", "refugee family"),
       #group = list("controls" = "male"),
       label = "tab:turk_reg_no_ctrls",
       title = "OLS regressions without controls (Turkey)",
       file = "Tables/Turkey Regressions.tex")

# Table F10 - Alternate models for binary outcomes
tab.turk.logit <- etable(
  regs.turk.log, regs.turk.logit, 
  tex = T, se.below = se_setting,
  family = F,
  headers = list("^" = c("OLS","OLS", "Logit", "Logit" )),
  keep = c("^treated$", "refugee family"),
  group = list("controls" = "male"), 
  label = "tab:turk_reg_logit",
  title = "Alternate models for letter and donation outcomes (Turkey)",
  file = "Tables/Turkey Regressions.tex")

# Table F11 - Preregistered set of controls 
tab.turk.pap <- etable(regs.turk.pap, tex = T, se.below = se_setting,
       keep = c("^treated$", "refugee family"),
       group = list("preregistered controls" = "male"), 
       label = "tab:turk_reg_pap",
       title = "OLS regression using the preregistered set of controls (Turkey)",
       file = "Tables/Turkey Regressions.tex")

# Table F12 - Interactions with all covariates

tab.turk.interact <- etable(regs.turk.interact, tex = T, se.below = se_setting,
       keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"),
       label = "tab:turk_reg_interact",
       title = "OLS regression interacting treatment with all covariates (Turkey)",
       file = "Tables/Turkey Regressions.tex")

# Table F13 - Matching
tab.turk.match <- etable(regs.turk.match, tex = T, se.below = se_setting,
       keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"), 
       label = "tab:turk_reg_match",
       title = "Weighted least squares regression on matched data (Turkey)",
       file = "Tables/Turkey Regressions.tex")
```

#### Cyprus 2018

###### Regressions

```{r}

# Main
regs.cyp.2018 <- c.2018 %>%
  feglm(data = ., 
        c(asylum_num, kyrenia) ~
          refugee_family*treat_parallel + ..ctrls.2018, cluster = "municipality")

# No controls
regs.cyp.2018.no.ctrls <- c.2018 %>%
  feglm(data = ., 
        c(asylum_num, kyrenia) ~
          refugee_family*treat_parallel, cluster = "municipality")

# Alternative set of controls
regs.cyp.2018.alt <- c.2018 %>%
  feglm(data = ., 
        c(asylum_num, kyrenia) ~
          refugee_family*treat_parallel + ..ctrls.2018.alt, cluster = "municipality")

# Interactions
regs.cyp.2018.interact <- c.2018 %>%
  feglm(data = ., 
        c(asylum_num, kyrenia) ~
          refugee_family*treat_parallel + treat_parallel*(..ctrls.2018), cluster = "municipality")

# Matching
regs.cyp.2018.match <- c.2018 %>%
  feglm(data = ., 
        c(asylum_num, kyrenia) ~
          refugee_family*treat_parallel + ..ctrls.2018, weights = ~ weights, cluster = "municipality")

```

##### Tables

```{r}
# Table F14 - Main regression
tab.cyp.2018 <- etable(regs.cyp.2018, tex = T, 
                       keep = c("^treated$", "refugee family"),
                       group = list("controls" = "male"),
                       se.below = se_setting,
                       label = "tab:cyp18_reg",
                       title = "All outcomes using OLS regression (Cyprus 2018)",
                       file = "Tables/Cyprus 2018 Regressions.tex",
                       replace = T)


# Table F15 - No controls
tab.cyp.2018.no.ctrls <- etable(regs.cyp.2018.no.ctrls, tex = T,
       keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"),
       label = "tab:cyp18_reg_no_ctrls",
       title = "OLS regressions without controls (Cyprus 2018)",
       file = "Tables/Cyprus 2018 Regressions.tex")

# Table F16 - Alternative set of controls
tab.cyp.2018.alt.ctr <- etable(regs.cyp.2018.alt, tex = T, se.below = se_setting,
                       keep = c("^treated$", "refugee family"),
                       group = list("additional controls" = "male"), 
                       label = "tab:cyp18_reg_extra",
                       title = "OLS regression using additional set of controls (Cyprus 2018)",
                       file = "Tables/Cyprus 2018 Regressions.tex")

# Table F17 - Interactions
tab.cyp.2018.interact <- etable(regs.cyp.2018.interact, tex = T, 
                                  se.below = se_setting,
                                  keep = c("^treated$", "refugee family"),
                                  group = list("controls" = "male"), 
                                  label = "tab:cyp18_reg_interact",
                                  title = "OLS regression interacting treatment with all covariates (Cyprus 2018)",
                                  file = "Tables/Cyprus 2018 Regressions.tex")


# Table F18 - Matching
tab.cyp.2018.match <- etable(regs.cyp.2018.match, tex = T, 
                             se.below = se_setting,
                             keep = c("^treated$", "refugee family"),
                             group = list("controls" = "male"), 
                             label = "tab:cyp18_reg_match",
                             title = "Weighted least squares regression on matched data (Cyprus 2018)",
                             file = "Tables/Cyprus 2018 Regressions.tex")
```

#### Cyprus 2021

##### Regressions

```{r}

# Main
regs.cyp.2021 <- c.2021 %>%
  feglm(data = ., 
        c(concern, donate) ~
          refugee_family*treat_parallel + ..ctrls.2021)

# No controls
regs.cyp.2021.no.ctrls <- c.2021 %>%
  feglm(data = .,
        c(concern, donate) ~
          refugee_family*treat_parallel)

# Alternatives for binary outcomes
regs.cyp.2021.log <- c.2021 %>%
  feglm(data = ., 
        c(donation_amount, donation_amount_log) ~
          refugee_family*treat_parallel + ..ctrls.2021)

regs.cyp.2021.logit <- c.2021 %>%
  feglm(data = ., 
        donate ~ refugee_family*treat_parallel + ..ctrls.2021, 
        family = binomial())


# Interactions
regs.cyp.2021.interact <- c.2021 %>%
  feglm(data = ., 
        c(concern, donate) ~
          refugee_family*treat_parallel + treat_parallel*(..ctrls.2021))

# Matching
regs.cyp.2021.match <- c.2021 %>%
  feglm(data = ., 
        c(concern, donate) ~
          refugee_family*treat_parallel + ..ctrls.2021, weights = ~ weights)
```

##### Tables

```{r}
# Table F19 - Main regression
tab.cyp.2021 <- etable(regs.cyp.2021, tex = T, 
                       keep = c("^treated$", "refugee family"),
                       group = list("controls" = "male"),
                       se.below = se_setting,
                       label = "tab:cyp21_reg",
                       title = "All outcomes using OLS regression (Cyprus 2021)",
                       file = "Tables/Cyprus 2021 Regressions.tex",
                       replace = T)


# Table F20 - No controls
tab.cyp.2021.no.ctrls <- etable(regs.cyp.2021.no.ctrls, tex = T,
       keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"),
       label = "tab:cyp21_reg_no_ctrls",
       title = "OLS regressions without controls (Cyprus 2021)",
       file = "Tables/Cyprus 2021 Regressions.tex")


# Table F21 - Alternatives for binary outcomes
tab.cyp.2021.logit <- etable(regs.cyp.2021.log, 
  regs.cyp.2021.logit, 
  tex = T, 
  family = F,
  headers = list("^" = c("OLS", "OLS", "Logit")),
  se.below = se_setting,
  keep = c("^treated$", "refugee family"),
  group = list("controls" = "male"), 
  label = "tab:cyp21_reg_logit",
  title = "Alternate models for the donation outcome (Cyprus 2021)",
  file = "Tables/Cyprus 2021 Regressions.tex")



# Table F22 - Interactions with all covariates

tab.cyp.2021.interact <- etable(regs.cyp.2021.interact, tex = T, 
                                se.below = se_setting,
       keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"), 
       label = "tab:cyp21_reg_interact",
       title = "OLS regression interacting treatment with all covariates (Cyprus 2021)",
       file = "Tables/Cyprus 2021 Regressions.tex")


# Table F23 - Matching
tab.cyp.2021.match <- etable(regs.cyp.2021.match, tex = T, 
                             se.below = se_setting,
       keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"), 
       label = "tab:cyp21_reg_match",
       title = "Weighted least squares regression on matched data (Cyprus 2021)",
       file = "Tables/Cyprus 2021 Regressions.tex")
```

#### Cyprus 2022

##### Regressions

```{r}

# Main model
regs.cyp.2022 <- c.2022 %>% 
  feglm(data = ., 
        c(children, families, 
          open_camp, permits, 
          admissions, single_men, att_mean, letter) ~ 
          refugee_family*treat_parallel + ..ctrls.2022)

# Main model (first gen excluded)
regs.cyp.2022.nome <- c.2022.nome %>% 
  feglm(data = ., 
        c(children, families, 
          open_camp, permits, 
          admissions, single_men, att_mean, letter) ~ 
          refugee_family*treat_parallel + ..ctrls.2022)

# No controls
regs.cyp.2022.no.ctrls <- c.2022 %>%
  feglm(data = .,
        c(children, families,
          open_camp, permits,
          admissions, single_men, att_mean, letter) ~
          refugee_family*treat_parallel)

# No controls (first gen excluded)
regs.cyp.2022.no.ctrls.nome <- c.2022.nome %>%
  feglm(data = .,
        c(children, families,
          open_camp, permits,
          admissions, single_men, att_mean, letter) ~
          refugee_family*treat_parallel)

# Alternatives for binary outcomes
regs.cyp.2022.logit <- c.2022 %>% 
  feglm(data = ., letter ~ refugee_family*treat_parallel + ..ctrls.2022,
        family = binomial())

# Alternatives for binary outcomes (first gen excluded)
regs.cyp.2022.logit.nome <- c.2022.nome %>% 
  feglm(data = ., letter ~ refugee_family*treat_parallel + ..ctrls.2022,
        family = binomial())

# Excluding families who were both displaced and suffered violence
regs.cyp.2022.ndd <- c.2022 %>% 
  filter(violence_family + refugee_family <2) %>%
  feglm(data = ., 
        c(children, families, 
          open_camp, permits, 
          admissions, single_men, att_mean, letter) ~ 
          refugee_family*treat_parallel + ..ctrls.2022)
# Excluding families who were both displaced and suffered violence (first gen excluded)
regs.cyp.2022.ndd.nome <- c.2022.nome %>% 
  filter(violence_family + refugee_family <2) %>%
  feglm(data = ., 
        c(children, families, 
          open_camp, permits, 
          admissions, single_men, att_mean, letter) ~ 
          refugee_family*treat_parallel + ..ctrls.2022)


# Attention check
regs.cyp.2022.check <- c.2022 %>% 
  filter(attn_check != "fail") %>%
  feglm(data = ., 
        c(children, families, 
          open_camp, permits, 
          admissions, single_men, att_mean, letter) ~ 
          refugee_family*treat_parallel + ..ctrls.2022)


# Attention check (first gen excluded)

regs.cyp.2022.check.nome <- c.2022.nome %>% 
  filter(attn_check != "fail") %>%
  feglm(data = ., 
        c(children, families, 
          open_camp, permits, 
          admissions, single_men, att_mean, letter) ~ 
          refugee_family*treat_parallel + ..ctrls.2022)

# Interaction
regs.cyp.2022.interact <- c.2022 %>% 
  feglm(data = ., 
        c(children, families, 
          open_camp, permits, 
          admissions, single_men, att_mean, letter) ~ 
          refugee_family*treat_parallel + treat_parallel*(..ctrls.2022))

# Interaction (first gen excluded)
regs.cyp.2022.interact.nome <- c.2022.nome %>% 
  feglm(data = ., 
        c(children, families, 
          open_camp, permits, 
          admissions, single_men, att_mean, letter) ~ 
          refugee_family*treat_parallel + treat_parallel*(..ctrls.2022))

# Matching
regs.cyp.2022.match <- c.2022 %>%
  feglm(data = . , 
        c(children, families, open_camp,
          permits, admissions, single_men, att_mean,
          letter) ~ 
          refugee_family*treat_parallel + ..ctrls.2022, 
        weights = ~ weights)

# Matching (first gen excluded)
regs.cyp.2022.match.nome <- c.2022.nome %>%
  feglm(data = . , 
        c(children, families, open_camp,
          permits, admissions, single_men, att_mean,
          letter) ~ 
          refugee_family*treat_parallel + ..ctrls.2022, 
        weights = ~ weights)

```

##### Tables

```{r}

# Table F24 - Main models
table.cyp.2022 <- 
  etable(regs.cyp.2022, tex = T, se.below = se_setting,
         keep = c("^treated$", "refugee family"),
         group = list("controls" = "male"), 
         label = "tab:cyp22_reg",
         title = "All outcomes using OLS regression (Cyprus 2022)",
         file = "Tables/Cyprus 2022 Regressions A.tex",
         replace = T)
# Table F25 - Main models (w/o first gen refugees)
table.cyp.2022.nome <- 
  etable(regs.cyp.2022.nome, tex = T, se.below = se_setting,
         keep = c("^treated$", "refugee family"),
         group = list("controls" = "male"), 
         label = "tab:cyp22_reg_firstgen",
         title = "All outcomes using OLS regression (Cyprus 2022 with first generation Greek Cypriot refugees excluded)",
         file = "Tables/Cyprus 2022 Regressions A.tex")

# Table F26 - No controls
tab.cyp.2022.no.ctrls <- etable(regs.cyp.2022.no.ctrls, tex = T,
       keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"),
       label = "tab:cyp22_reg_no_ctrls",
       title = "OLS regressions without controls (Cyprus 2022)",
       file = "Tables/Cyprus 2022 Regressions A.tex")

# Table F27 - No controls (w/o first gen refugees)
tab.cyp.2022.no.ctrls.nome <- etable(regs.cyp.2022.no.ctrls.nome, tex = T,
       keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"),
       label = "tab:cyp22_reg_no_ctrls_firstgen",
       title = "OLS regressions without controls (Cyprus 2022 with first generation Greek Cypriot refugees excluded)",
       file = "Tables/Cyprus 2022 Regressions A.tex")

# Table F28 - Alternative models for binary outcomes
table.cyp.2022.logit <- 
  etable(regs.cyp.2022.logit, tex = T, se.below = se_setting,
         keep = c("^treated$", "refugee family"),
         group = list("controls" = "male"), 
         label = "tab:cyp22_reg_logit",
         title = "Alternative models for binary outcomes (Cyprus 2022)",
         file = "Tables/Cyprus 2022 Regressions A.tex")

# Table F29 - Alternative models for binary outcomes (w/o first gen refugees)
table.cyp.2022.logit.nome <- 
  etable(regs.cyp.2022.logit.nome, tex = T, se.below = se_setting,
         keep = c("^treated$", "refugee family"),
         group = list("controls" = "male"), 
         label = "tab:cyp22_reg_logit_firstgen",
         title = "Alternative models for binary outcomes (Cyprus 2022 with first generation Greek Cypriot refugees excluded)",
         file = "Tables/Cyprus 2022 Regressions A.tex")


# Table F30 - Excluding families who were both displaced and suffered violence
table.cyp.2022.ndd <- 
  etable(regs.cyp.2022, tex = T, se.below = se_setting,
         keep = c("^treated$", "refugee family"),
         group = list("controls" = "male"), 
         label = "tab:cyp22_reg_ndd",
         title = "OLS regression excluding families who were both displaced and suffered violence (Cyprus 2022)",
         file = "Tables/Cyprus 2022 Regressions B.tex",
         replace = T)

# Table F31 - Excluding families who were both displaced and suffered violence (w/o first gen refugees)
table.cyp.2022.ndd.nome <- 
  etable(regs.cyp.2022.nome, tex = T, se.below = se_setting,
         keep = c("^treated$", "refugee family"),
         group = list("controls" = "male"), 
         label = "tab:cyp22_reg_ndd_firstgen",
         title = "OLS regression excluding families who were both displaced and suffered violence (Cyprus 2022 with first generation Greek Cypriot refugees excluded)",
         file = "Tables/Cyprus 2022 Regressions B.tex")

# Table F32 - Filering with post-treatment attention checks
tab.cyp.2022.check <- etable(regs.cyp.2022.check, tex = T, se.below = se_setting,
       keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"), 
       label = "tab:cyp22_reg_check",
       title = "OLS regression with post-treatment attention checks (Cyprus 2022)",
       file = "Tables/Cyprus 2022 Regressions B.tex")

# Table F33 - Filtering with post-treatment attention checks (w/o first gen refugees)
tab.cyp.2022.check.nome <- etable(regs.cyp.2022.check.nome, tex = T, se.below = se_setting,
       keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"), 
       label = "tab:cyp22_reg_check_firstgen",
       title = "OLS regression with post-treatment attention checks (Cyprus 2022 with first generation Greek Cypriot refugees excluded)",
       file = "Tables/Cyprus 2022 Regressions B.tex")

# Table F34 - Interacting treatment with all covariates
tab.cyp.2022.interact <- etable(regs.cyp.2022.interact, tex = T, 
                                  se.below = se_setting,
         keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"), 
       label = "tab:cyp22_reg_interact",
       title = "OLS regression interacting treatment with all covariates (Cyprus 2022)",
       file = "Tables/Cyprus 2022 Regressions B.tex")

# Table F35 - Interacting treatment with all covariates (w/o first gen refugees)
tab.cyp.2022.interact.nome <- etable(regs.cyp.2022.interact.nome, tex = T, se.below = se_setting,
         keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"), 
       label = "tab:cyp22_reg_interact_firstgen",
       title = "OLS regression interacting treatment with all covariates (Cyprus 2022 with first generation Greek Cypriot refugees excluded)",
       file = "Tables/Cyprus 2022 Regressions B.tex")

# Table F36 - Matching 
tab.cyp.2022.match <- etable(regs.cyp.2022.match, tex = T, se.below = se_setting,
       keep = c("^treated$", "refugee family"),
       group = list("controls" = "male"), 
       label = "tab:cyp22_reg_match",
       title = "Weighted least squares regression on matched data  (Cyprus 2022)",
       file = "Tables/Cyprus 2022 Regressions B.tex")

# Table F37 - Matching (w/o first gen refugees)
table.cyp.2022.match.nome <- 
  etable(regs.cyp.2022.match.nome, 
         tex = T, se.below = se_setting,
         keep = c("^treated$", "refugee family"),
         group = list("controls" = "male"), 
         label = "tab:cyp22_reg_match_firstgen",
         title = "Weighted least squares regression on matched data (Cyprus 2022 with first generation Greek Cypriot refugees excluded)",
         file = "Tables/Cyprus 2022 Regressions B.tex")
```

## Section G - Cyprus Acknowledgement

### Regressions

```{r}
M.cyp.ACK <- c.3arms %>%
  mutate(drop_first_gen = case_when(first_gen_refugee==1~NA,
                                 T ~ T)) %>%
  feglm(data = ., 
        c(attitude_mean, letter) ~ 
          refugee_family*treat_parallel +  
          refugee_family*treat_acknowledge +
          ..ctrls.2022 + sw0(drop_first_gen))
```

### Tables

```{r}
etable(M.cyp.ACK, 
       tex = T, 
       keep = c("parallel", "acknowledge", "refugee family"),
       group = list("controls" = "male"), 
       se.below = F,
       label = "tab:main_plot_ACK",
         title = "OLS regressions with acknowledgement treatment (Cyprus 2022)",
         file = "Tables/Cyprus Acknowledge Main Regressions.tex",
       replace = T,
       extralines = list("First Gen. Refugees" = c("included", "excluded", "included", "excluded"))
       )
```
